﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentValidation;
using Micrhard.FMCG.Server.Models;
using FluentValidation.Results;
using Micrhard.FMCG.Server.Msg;

namespace Micrhard.FMCG.Server.Validator
{
    public class FakeCodeModelValidator : AbstractValidator<FakeCodeModel>
    {
        public FakeCodeModelValidator()
        {
            RuleSet("Insert", () =>
            {
                Custom(u =>
                {
                    if (u.SN == string.Empty)
                    {
                        return new ValidationFailure("ImportError", FakeCodeModelMsg.NeedSN);
                    }
                    if (u.Code == Guid.Empty)
                    {
                        return new ValidationFailure("ImportError", FakeCodeModelMsg.NeedCode);
                    }
                    return null;
                });
            });

            RuleSet("Update", () =>
            {
                Custom(u =>
                 {
                     if (u.IpAddress == string.Empty)
                     {
                         return new ValidationFailure("IpAddress", FakeCodeModelMsg.NeedIpAddress);
                     }
                     return null;
                 });
            });
        }
    }
}
